//
//  ModelProductCpi.m
//  MexicoLoan
//
//  Created by WXP on 2025/3/9.
//
//

#import "ModelProductCpi.h"

NSString *const kModelProductCpiId = KEY_id;
NSString *const kModelProductCpiName = KEY_name;
NSString *const kModelProductCpiMinAmount = KEY_minAmount;
NSString *const kModelProductCpiSlogan = KEY_slogan;
NSString *const kModelProductCpiDisplay = KEY_display;
NSString *const kModelProductCpiCapType = KEY_capType;
NSString *const kModelProductCpiMinFeeRate = KEY_minFeeRate;
NSString *const kModelProductCpiExternalLink = KEY_externalLink;
NSString *const kModelProductCpiCapPushed = KEY_capPushed;
NSString *const kModelProductCpiMaxAmount = KEY_maxAmount;
NSString *const kModelProductCpiTermUnit = KEY_termUnit;
NSString *const kModelProductCpiCapTotal = KEY_capTotal;
NSString *const kModelProductCpiMaxFeeRate = KEY_maxFeeRate;
NSString *const kModelProductCpiTerm = KEY_term;
NSString *const kModelProductCpiAuthConfig = KEY_authConfig;
NSString *const kModelProductCpiRemark = KEY_remark;
NSString *const kModelProductCpiCapPer = KEY_capPer;
NSString *const kModelProductCpiPeriods = KEY_periods;

@interface ModelProductCpi ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation ModelProductCpi

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize name = _name;
@synthesize minAmount = _minAmount;
@synthesize slogan = _slogan;
@synthesize display = _display;
@synthesize capType = _capType;
@synthesize minFeeRate = _minFeeRate;
@synthesize externalLink = _externalLink;
@synthesize capPushed = _capPushed;
@synthesize maxAmount = _maxAmount;
@synthesize termUnit = _termUnit;
@synthesize capTotal = _capTotal;
@synthesize maxFeeRate = _maxFeeRate;
@synthesize term = _term;
@synthesize authConfig = _authConfig;
@synthesize remark = _remark;
@synthesize capPer = _capPer;
@synthesize periods = _periods;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
        self.internalBaseClassIdentifier = [[self objectOrNilForKey:kModelProductCpiId fromDictionary:dict] doubleValue];
        self.name = [self objectOrNilForKey:kModelProductCpiName fromDictionary:dict];
        self.minAmount = [[self objectOrNilForKey:kModelProductCpiMinAmount fromDictionary:dict] doubleValue];
        self.slogan = [self objectOrNilForKey:kModelProductCpiSlogan fromDictionary:dict];
        self.display = [[self objectOrNilForKey:kModelProductCpiDisplay fromDictionary:dict] doubleValue];
        self.capType = [[self objectOrNilForKey:kModelProductCpiCapType fromDictionary:dict] doubleValue];
        self.minFeeRate = [[self objectOrNilForKey:kModelProductCpiMinFeeRate fromDictionary:dict] doubleValue];
        self.externalLink = [self objectOrNilForKey:kModelProductCpiExternalLink fromDictionary:dict];
        self.capPushed = [[self objectOrNilForKey:kModelProductCpiCapPushed fromDictionary:dict] doubleValue];
        self.maxAmount = [[self objectOrNilForKey:kModelProductCpiMaxAmount fromDictionary:dict] doubleValue];
        self.termUnit = [[self objectOrNilForKey:kModelProductCpiTermUnit fromDictionary:dict] doubleValue];
        self.capTotal = [[self objectOrNilForKey:kModelProductCpiCapTotal fromDictionary:dict] doubleValue];
        self.maxFeeRate = [[self objectOrNilForKey:kModelProductCpiMaxFeeRate fromDictionary:dict] doubleValue];
        self.term = [[self objectOrNilForKey:kModelProductCpiTerm fromDictionary:dict] doubleValue];
        self.authConfig = [self objectOrNilForKey:kModelProductCpiAuthConfig fromDictionary:dict];
        self.remark = [self objectOrNilForKey:kModelProductCpiRemark fromDictionary:dict];
        self.capPer = [[self objectOrNilForKey:kModelProductCpiCapPer fromDictionary:dict] doubleValue];
        self.periods = [[self objectOrNilForKey:kModelProductCpiPeriods fromDictionary:dict] doubleValue];
    }
    return self;
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kModelProductCpiId];
    [mutableDict setValue:self.name forKey:kModelProductCpiName];
    [mutableDict setValue:[NSNumber numberWithDouble:self.minAmount] forKey:kModelProductCpiMinAmount];
    [mutableDict setValue:self.slogan forKey:kModelProductCpiSlogan];
    [mutableDict setValue:[NSNumber numberWithDouble:self.display] forKey:kModelProductCpiDisplay];
    [mutableDict setValue:[NSNumber numberWithDouble:self.capType] forKey:kModelProductCpiCapType];
    [mutableDict setValue:[NSNumber numberWithDouble:self.minFeeRate] forKey:kModelProductCpiMinFeeRate];
    [mutableDict setValue:self.externalLink forKey:kModelProductCpiExternalLink];
    [mutableDict setValue:[NSNumber numberWithDouble:self.capPushed] forKey:kModelProductCpiCapPushed];
    [mutableDict setValue:[NSNumber numberWithDouble:self.maxAmount] forKey:kModelProductCpiMaxAmount];
    [mutableDict setValue:[NSNumber numberWithDouble:self.termUnit] forKey:kModelProductCpiTermUnit];
    [mutableDict setValue:[NSNumber numberWithDouble:self.capTotal] forKey:kModelProductCpiCapTotal];
    [mutableDict setValue:[NSNumber numberWithDouble:self.maxFeeRate] forKey:kModelProductCpiMaxFeeRate];
    [mutableDict setValue:[NSNumber numberWithDouble:self.term] forKey:kModelProductCpiTerm];
    [mutableDict setValue:self.authConfig forKey:kModelProductCpiAuthConfig];
    [mutableDict setValue:self.remark forKey:kModelProductCpiRemark];
    [mutableDict setValue:[NSNumber numberWithDouble:self.capPer] forKey:kModelProductCpiCapPer];
    [mutableDict setValue:[NSNumber numberWithDouble:self.periods] forKey:kModelProductCpiPeriods];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}

@end
